package cn.xfdzx.android.apps.shop.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author gzk
 * @date 2020/5/10 0010
 * description：
 */
public class IArcView extends View {

    private static String TAG = "自定义绘图";
    private int color;

    public IArcView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public IArcView(Context context) {
        super(context);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        float width = getWidth();
        float height = getHeight();
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(color);
        paint.setStrokeWidth(1);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL);
//        RectF rectF = new RectF(0, 0, width, height);
        RectF bottom = new RectF(0, 0, width, height / 5 * 4);
        RectF rect1 = new RectF(0, height / 5 * 3, width, height);
//        RectF rect2 = new RectF(width/2, height/10*9, width, height);
        // 画弧形
        canvas.drawArc(rect1, 0, 360, false, paint);
//        canvas.drawArc(rect2, 0, 360, false, paint);
        // 画底部矩形
        canvas.drawRect(bottom, paint);
        //圆弧描边
//        paint.setColor(StringToColor("#646e91"));
        paint.setStyle(Paint.Style.STROKE);
//        canvas.drawArc(rect, 0, 360, false, paint);
    }

    /**
     * #颜色转16进制颜色
     *
     * @param str {String} 颜色
     * @return
     */
    private int StringToColor(String str) {
        return 0xff000000 | Integer.parseInt(str.substring(2), 16);
    }

    public void setToColor(int color) {
        this.color=color;
        invalidate();
    }

    public void setStringColor(String color) {
        this.color=Color.parseColor(color);
        invalidate();
    }
}
